import pygame
from pygame.locals import *
import speech

class Menu:
    def __init__(self):
        self.items = []
        self.index = 1
    def AddItem(self, tup):
        self.items += tup
    def SpeakItem(self):
        """
        Speaking the item at the current index requires that we access the tupal. To keep from having to rewrite this code, you can use this function to speak the item where the current index is.
        """
        speech.speak(items[self.index][0], True)
    def NextItem(self):
        """
        This function is used to increase the index--it should be bound to down and right arrow events.
        """
        if self.index == len(items):
            #todo: add some sort of bottom of list here.
            return
        else:
            self.index += 1
            self.SpeakItem()
    def PreviousItem(self):
        """
        This function is used to decrease the index in the menu. It should be bound to the left and up arrow events.
        """
        if self.index == 1:
            #todo: add a top of list notification here.
            return
        else:
            self.index -= 1
            self.SpeakItem()
    def ActivateItem():
        """
        Calls the callback that is defined at the current index.
        """
        (self.items[self.index][1])(self.game)
        self.Kill()
    def Show(self, game, message):
        game.menu = self
        self.game = game
        speech.speak(message, True)
    def Kill(self):
        self.game.menu = None
